define(["../common"], function() {

	var delDoPath = g_firmDomain + "/companyMember/delDo/json";
	var cmId = $("#cmId").val();

	//事件：删除企业管理员
	$(document).on("click", "[id^='del_']", function() {
		var id = ($(this).attr("id").split("_"))[1];// memberId
		var $item = $("#item_" + id);
		if ($item.doing()) return;
		
		var message;
		if (id === cmId) {
			message = "确定要删除自己吗？<br/>删除后您将不再拥有该企业的管理权限！";
		} else {
			var delMemberName = $("#memberName_" + id).html();
			message = "确定要删除管理员 " + delMemberName + " 吗？";
		}
		
		var msgboxConfig = {
			id: "del_" + id,
			type: 'confirm',
			content: message,
			title: "提示",
			onClose: function() {
				if (!this.val()) {
					return;
				}
				$item.showMsg("删除管理员...", 'load', true);
				$item.fadeTo(null,0.1);
				$.getJSON(delDoPath, {memberId: id}, function(data) {
					if (data.status === 0) {
						if (id === cmId) {
							setTimeout(function() {
								location.href = g_domain + "/member/logoutDo";
							}, 800); // 延时
		
						} else {
							$item.fadeOut(function() {
								$item.showMsg();
								$(this).remove();
							});
						}
					} else {
						$item.showMsg(data.message, 'error');
						$item.fadeTo('fast',1);
					}
				});
			}
		};
		
		loadjs(["msgbox"], function() {
			$.msgbox(msgboxConfig);
		});
		
	});
});
